import com from "./common"
import $ from "jquery"
let Scroll = {
  _loadCheck : true,
  PageSize:1,
  PageNum:5,
  StartScroll:function (obj) {
    let self = this;
    $(window).scroll(function(){
      let range = 40;
      let srollPos = $(window).scrollTop(); //滚动条距顶部距离(页面超出窗口的高度)
      let totalheight = parseFloat($(window).height()) + parseFloat(srollPos);
      // 当页面滑到底部时
      if(($(document).height()-range) <= totalheight && self._loadCheck) {
        $(".load").html("数据加载中,请稍后");
        self._loadCheck = false;
        let data = {
          PageSize:self.PageSize,
        }
        $.extend(data,obj.data);
        com.ajax({
          url:obj.url,
          data:data,
          ok:function(dat){
            console.log(dat);
            Scroll._loadCheck = true;
            self.PageSize ++ ;
            console.log(this.data);
            obj.callback(dat["res"]);
            if(dat["res"].length < self.PageNum){
              self._loadCheck = false;
              $(".load").html("数据加载完成");
              setTimeout(function(){
                $(".load").remove()
              },2000)
            }
          },
        })
      }else{
      }
    });
  }
}
export default Scroll